package logic

import (
	"context"
	"weixin/models/mysql"

	"weixin/weixinrpc/internal/svc"
	"weixin/weixinrpc/weixinrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *weixinrpc.UserListRequest) (*weixinrpc.UserListResponse, error) {
	// todo: add your logic here and delete this line

	var user []mysql.User
	mysql.DB.Debug().Find(&user)

	var userList []*weixinrpc.UserList
	for _, list := range user {
		list := weixinrpc.UserList{
			Nickname:  list.Nickname,
			Name:      list.Name,
			HeadImage: list.HeadImage,
			Tel:       list.Tel,
			Uptime:    list.Uptime,
			Price:     float32(list.Price),
		}
		userList = append(userList, &list)
	}

	return &weixinrpc.UserListResponse{
		List: userList,
	}, nil
}
